<template>
  <el-dialog
    width="500px"
    title="添加备注"
    :visible.sync="dialogVisible"
    :close-on-click-modal="false"
  >
    <el-form
      :model="form"
      :rules="rules"
      ref="ruleForm"
      label-width="100px"
    >
      <el-form-item label="订单编号">
        <el-input
          v-model="form.orderId"
          disabled
        ></el-input>
      </el-form-item>
      <el-form-item
        label="备注"
        prop="remark"
      >
        <el-input
          type="textarea"
          :rows="4"
          placeholder="备注"
          v-model="form.remark"
        >
        </el-input>
      </el-form-item>
    </el-form>
    <div
      slot="footer"
      class="dialog-footer"
    >
      <el-button
        size="small"
        @click="dialogVisible = false"
      >取 消</el-button>
      <el-button
        size="small"
        type="primary"
        @click="submit"
      >确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { setOrderRemark } from "@/api/order";
export default {
  props: ['orderId'],
  data() {
    return {
      form: {
        orderId: "",
        remark: ''
      },
      rules: {
        remark: [
          { required: true, message: '备注不能为空', trigger: 'blur' }
        ]
      },
      dialogVisible: false
    }
  },
  methods: {
    submit() {
      this.$refs['ruleForm'].validate((valid) => {
        if (valid) {
          setOrderRemark({ ...this.form }).then(res => {
            this.dialogVisible = false;
            this.$emit('getList', true);
          })
        } else {
          this.$message({
            message: "请检查表单错误",
            type: "error"
          });
          return false;
        }
      });
    }
  },
  watch: {
    dialogVisible(val) {
      if (val) {
        this.form.orderId = this.orderId;
        this.form.remark = '';
      } else {
        this.$refs['ruleForm'].resetFields();
      }
    }
  }
}
</script>

<style lang="scss" scoped>
</style>
